package com.cmict.data.form.api.util;


import com.cmict.data.form.api.service.SysCurrencyService;
import com.cmict.data.form.api.service.SysFormService;
import com.cmict.data.system.api.dept.DeptApi;
import com.cmict.data.system.api.dept.PostApi;
import com.cmict.data.system.api.dict.DictDataApi;
import com.cmict.data.system.api.user.AdminUserApi;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * @description: 导入字段类型工具类
 * @author: qiaoyu
 * @create: 2022-07-08 22:57
 **/
@Component
public class IsDateInUtil {

    @Autowired
    private SysFormService sysFormService;
    private static SysFormService realsysFormService;

    @Autowired
    private SysCurrencyService sysCurrencyService;
    private static SysCurrencyService realsysCurrencyService;

    @Autowired
    private DictDataApi dictDataService;
    private static DictDataApi realdictDataService;

    @Autowired
    private DeptApi deptService;
    private static DeptApi realdeptService;

    @Autowired
    private AdminUserApi adminUserService;
    private static AdminUserApi realadminUserService;

    @Autowired
    private PostApi postService;
    private static PostApi realpostService;

    @PostConstruct
    public void init() {
        realsysFormService = sysFormService;
        realsysCurrencyService = sysCurrencyService;
        realdictDataService = dictDataService;
        realdeptService = deptService;
        realadminUserService = adminUserService;
        realpostService = postService;
    }
    static Map<Object,Object> datechange(String value, String datatype) {
        String req = "";
        boolean isselect = true;
        String returnValue = "";
        if("yyyy".equals(datatype)){
            try{
               /* SimpleDateFormat sdf = new SimpleDateFormat("yyyy");
                Date date = sdf.parse(value);
                SimpleDateFormat sdfr = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                returnValue = sdfr.format(date);*/
                returnValue = value + "-01-01 00:00:00";
            }catch (Exception e){
                req = "日期格式不正确";
                isselect = false;
            }
        }
        if("yyyy-MM-dd".equals(datatype)){
            try{
                returnValue = value + " 00:00:00";
            }catch (Exception e){
                req = "日期格式不正确";
                isselect = false;
            }
        }
        if("yyyy-MM".equals(datatype)){
            try{
                returnValue = value + "-01 00:00:00";
            }catch (Exception e){
                req = "时间格式不正确";
                isselect = false;
            }
        }
        if("yyyy-MM-dd HH:mm:ss".equals(datatype)){
            try{
                returnValue = value;
            }catch (Exception e){
                req = "时间格式不正确";
                isselect = false;
            }
        }
        Map<Object,Object> map = new HashMap<>();
        map.put("req",req);
        map.put("isselect",isselect);
        map.put("value",returnValue);
        return map;
    }
}

